import { Navigate, useLocation } from "react-router-dom";

export const ProtectRoute = ({ children }) => {
  const location = useLocation();
  const token = localStorage.getItem("token") ?? "";
  if (!token) {
    return <Navigate to="/login" state={{ from: location }} />;
  } else {
    return children;
  }
};
